package com.wang.vedio.adapter.index;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vondear.rxtool.RxDeviceTool;
import com.vondear.rxtool.RxImageTool;
import com.wang.vedio.R;
import com.wang.vedio.net.entity.VideoBean;
import com.wang.vedio.net.rxjava.HttpMethods;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 *
 * @time 2020/4/7
 */
public class TuiJianAdapter extends BaseMultiItemQuickAdapter<VideoBean, BaseViewHolder> {
    public static final int ITEM_TYPE_VIDEO = 0;
    public static final int ITEM_TYPE_ADVERTISING = 1;

    //R.layout.gyss_item_tuijian_list
    public TuiJianAdapter(@Nullable List<VideoBean> data) {
        super(data);
        addItemType(ITEM_TYPE_VIDEO, R.layout.item_tuijian_video);
        addItemType(ITEM_TYPE_ADVERTISING, R.layout.item_tuijian_ad);
    }

    private String key;

    public void setKey(String key) {
        this.key = key;
        notifyDataSetChanged();
    }


    @Override
    protected void convert(@NotNull BaseViewHolder helper, VideoBean videoBean) {
        switch (helper.getItemViewType()) {
            case ITEM_TYPE_VIDEO:

                helper.setText(R.id.videoBfcs0, videoBean.getPlayNum());
                helper.setText(R.id.videoSeconds0,videoBean.getVedioSeconds());
                helper.setText(R.id.videoTitle0, videoBean.getTitle());

                helper.getView(R.id.vipTv).setVisibility("是".equals(videoBean.getSfVip())? View.VISIBLE:View.GONE);

                ImageView imageView = helper.getView(R.id.videoImg0);
                int imgWidth = (RxDeviceTool.getScreenWidth(mContext)- RxImageTool.dp2px(48))/2;
                ViewGroup.LayoutParams params = imageView.getLayoutParams();
                params.height = imgWidth*3/4;
                params.width = imgWidth;
                imageView.setLayoutParams(params);
                Glide.with(imageView)
                        .load(HttpMethods.BASE_URL+videoBean.getVedioFmImg())
                        .apply(RequestOptions.bitmapTransform(new MultiTransformation<>(new CenterCrop(),new RoundedCorners(30))))
                        .into(imageView);
                break;
            case ITEM_TYPE_ADVERTISING:
                ImageView imageViewAd = helper.getView(R.id.image);
                Glide.with(imageViewAd)
                        .load(HttpMethods.BASE_URL+videoBean.getVedioFmImg())
                        .apply(RequestOptions.bitmapTransform(new MultiTransformation<>(new CenterCrop(),new RoundedCorners(30))))
                        .into(imageViewAd);
                break;
            default:
                break;
        }
    }

    private String getTime(String seconds){
        long sec = Long.parseLong(seconds);
        int h = (int) (sec / 3600);
        int m = (int) ((sec % 3600)/60);
        int secs = (int) ((sec % 3600)%60);
        return (h<10?"0"+h:h+"")+":"+(m<10?"0"+m:m+"")+":"+(secs<10?"0"+secs:secs+"");
    }
}
